import rospy
from sensor_msgs.msg import Image
from cv_bridge import CvBridge, CvBridgeError
import cv2
bridge = CvBridge()
i = 0

def image_callback(msg):
    try:
      cv_image = bridge.imgmsg_to_cv2(msg, "bgr8")
    except CvBridgeError as e:
      print(e)
 
    global i
    i+=1
    cv2.imshow("cv_image",cv_image)
    cv2.waitKey(1)

    if(i%5 == 0):
        cv2.imwrite(str(i/5)+'.png',cv_image)

 

if __name__ == "__main__":
    rospy.init_node("create_dataset")
    image_sub = rospy.Subscriber("/camera0/image_raw",Image,image_callback,queue_size=5)
    rospy.spin()